package com.transitionseverywhere;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.TimeInterpolator;
import android.graphics.PointF;
import android.os.Build;
import android.view.View;
import com.transitionseverywhere.Transition;
import com.transitionseverywhere.utils.AnimatorUtils;
import com.transitionseverywhere.utils.PointFProperty;

/* loaded from: classes.dex */
public class TranslationAnimationCreator {
    public static final PointFProperty<View> TRANSLATIONS_PROPERTY;

    static {
        if (Build.VERSION.SDK_INT >= 14) {
            TRANSLATIONS_PROPERTY = new PointFProperty<View>() { // from class: com.transitionseverywhere.TranslationAnimationCreator.1
                @Override // android.util.Property
                public void set(View view, PointF pointF) {
                    view.setTranslationX(pointF.x);
                    view.setTranslationY(pointF.y);
                }
            };
        } else {
            TRANSLATIONS_PROPERTY = null;
        }
    }

    public static Animator createAnimation(View view, TransitionValues transitionValues, int i, int i2, float f, float f2, float f3, float f4, TimeInterpolator timeInterpolator, Transition transition) {
        float f5;
        float f6;
        float translationX = view.getTranslationX();
        float translationY = view.getTranslationY();
        int[] iArr = (int[]) transitionValues.view.getTag(R.id.transitionPosition);
        if (iArr != null) {
            f6 = (iArr[1] - i2) + translationY;
            f5 = (iArr[0] - i) + translationX;
        } else {
            f5 = f;
            f6 = f2;
        }
        int round = i + Math.round(f5 - translationX);
        int round2 = i2 + Math.round(f6 - translationY);
        view.setTranslationX(f5);
        view.setTranslationY(f6);
        Animator ofPointF = AnimatorUtils.ofPointF(view, TRANSLATIONS_PROPERTY, f5, f6, f3, f4);
        if (ofPointF != null) {
            TransitionPositionListener transitionPositionListener = new TransitionPositionListener(view, transitionValues.view, round, round2, translationX, translationY);
            transition.addListener(transitionPositionListener);
            ofPointF.addListener(transitionPositionListener);
            AnimatorUtils.addPauseListener(ofPointF, transitionPositionListener);
            ofPointF.setInterpolator(timeInterpolator);
        }
        return ofPointF;
    }

    /* loaded from: classes.dex */
    private static class TransitionPositionListener extends AnimatorListenerAdapter implements Transition.TransitionListener {
        private final View mMovingView;
        private float mPausedX;
        private float mPausedY;
        private final int mStartX;
        private final int mStartY;
        private final float mTerminalX;
        private final float mTerminalY;
        private int[] mTransitionPosition;
        private final View mViewInHierarchy;

        @Override // android.animation.AnimatorListenerAdapter, android.animation.Animator.AnimatorListener
        public void onAnimationEnd(Animator animator) {
        }

        @Override // com.transitionseverywhere.Transition.TransitionListener
        public void onTransitionCancel(Transition transition) {
        }

        @Override // com.transitionseverywhere.Transition.TransitionListener
        public void onTransitionPause(Transition transition) {
        }

        @Override // com.transitionseverywhere.Transition.TransitionListener
        public void onTransitionResume(Transition transition) {
        }

        @Override // com.transitionseverywhere.Transition.TransitionListener
        public void onTransitionStart(Transition transition) {
        }

        private TransitionPositionListener(View view, View view2, int i, int i2, float f, float f2) {
            this.mMovingView = view;
            this.mViewInHierarchy = view2;
            this.mStartX = i - Math.round(this.mMovingView.getTranslationX());
            this.mStartY = i2 - Math.round(this.mMovingView.getTranslationY());
            this.mTerminalX = f;
            this.mTerminalY = f2;
            this.mTransitionPosition = (int[]) this.mViewInHierarchy.getTag(R.id.transitionPosition);
            if (this.mTransitionPosition != null) {
                this.mViewInHierarchy.setTag(R.id.transitionPosition, null);
            }
        }

        @Override // android.animation.AnimatorListenerAdapter, android.animation.Animator.AnimatorListener
        public void onAnimationCancel(Animator animator) {
            if (this.mTransitionPosition == null) {
                this.mTransitionPosition = new int[2];
            }
            this.mTransitionPosition[0] = Math.round(this.mStartX + this.mMovingView.getTranslationX());
            this.mTransitionPosition[1] = Math.round(this.mStartY + this.mMovingView.getTranslationY());
            this.mViewInHierarchy.setTag(R.id.transitionPosition, this.mTransitionPosition);
        }

        @Override // android.animation.AnimatorListenerAdapter, android.animation.Animator.AnimatorPauseListener
        public void onAnimationPause(Animator animator) {
            this.mPausedX = this.mMovingView.getTranslationX();
            this.mPausedY = this.mMovingView.getTranslationY();
            this.mMovingView.setTranslationX(this.mTerminalX);
            this.mMovingView.setTranslationY(this.mTerminalY);
        }

        @Override // android.animation.AnimatorListenerAdapter, android.animation.Animator.AnimatorPauseListener
        public void onAnimationResume(Animator animator) {
            this.mMovingView.setTranslationX(this.mPausedX);
            this.mMovingView.setTranslationY(this.mPausedY);
        }

        @Override // com.transitionseverywhere.Transition.TransitionListener
        public void onTransitionEnd(Transition transition) {
            this.mMovingView.setTranslationX(this.mTerminalX);
            this.mMovingView.setTranslationY(this.mTerminalY);
        }
    }
}
